package profilingapp.security;

import java.util.HashMap;
import java.util.Map;
import messageAPI.PerformanceInstrumentationServiceFactory;
import messageAPI.Core.IPerformanceInstrumentationService;
import messageAPI.Core.PerformanceEvent;

public class SecurityProvider {
	
	public boolean authenticate(String user, String password){		
		
		//Added manually for java api integration	
		startTimer();
		
		if(user.equals("tom") | user.equals("dick") | user.equals("harry"))
		{
			return true;
		}
		
		//Added manually for java api integration
		
		//Create Context values for this method
		Map<String,String> contextValues = new HashMap<String, String>();
		
		contextValues.put("user.argument", user);
		
		stopTimer(contextValues);
		
		return false;		
	}
	
	//Added manually for java api integration
	long startTime;
	
	//Added manually for java api integration
	private void startTimer()
	{
		startTime=System.currentTimeMillis();
    }
	
	//Added manually for java api integration
	private void stopTimer(Map<String,String> contextValues)
	{
		long endTime = System.currentTimeMillis();
	    
		messageAPI.PerformanceInstrumentationServiceFactory performanceInstrumentationServiceFactory = new PerformanceInstrumentationServiceFactory();
		IPerformanceInstrumentationService performanceInstrumentationService=performanceInstrumentationServiceFactory.GetPerformanceInstrumentationService();
		
		long value = (long) ((float)(endTime - startTime)/1000);
		
		PerformanceEvent performanceEvent = new PerformanceEvent("profilingapp.security.securityprovider.authenticate.duration",System.currentTimeMillis(),value);
		performanceEvent.ContextValues=contextValues;
		
		performanceInstrumentationService.sendEvent(performanceEvent);
		
		startTime=0;
	}

}
